<template>
    <h3>理财项目页面</h3>
    理财编号:
    <input type="text" v-model="info.Fid">
    理财名称:
    <input type="text" v-model="info.Fname">
    理财收益:
    <input type="text" v-model="info.Min">-
    <input type="text" v-model="info.Max">
    <button @click="PageShow" class="btn btn-success">查询</button>
    <table border="1" class="table-bordered">
        <tr>
            <td>理财编号</td>
            <td>理财名称</td>
            <td>年收益</td>
            <td>月收益</td>
            <td>最低金额</td>
            <td>理财人数</td>
            <td>风险等级</td>
            <td>操作</td>
        </tr>
        <tr v-for="i in data">
            <td>{{ i.F_Id }}</td>
            <td>{{ i.F_Name }}</td>
            <td>{{ i.F_ARY }}</td>
            <td>{{ (i.F_ARY/12).toFixed(2) }}%</td>
            <td>{{ i.F_MinMoney.toFixed(2) }}CNY</td>
            <td>{{ i.F_Number }}</td>
            <td>{{ i.F_Level }}</td>
            <td><a href="#" @click="Go(i.F_Id)">查看明细</a>
                </td>
        </tr>
    </table>
    <a href="#" @click='PageChange("F")'>首页</a>
    <a href="#" @click='PageChange("P")'>上一页</a>
    <a href="#" @click='PageChange("N")'>下一页</a>
    <a href="#" @click='PageChange("L")'>尾页</a>
    当前页数:{{ PageInfo.PageIndex }} 总页数:{{ PageInfo.PageCount }} 总记录数:{{ PageInfo.ReCount }}一页显示条数:{{ PageInfo.PageSize }}
    </template>
    <script setup lang="ts">
    import axios from 'axios';
    import {ref,onMounted} from 'vue'
    import {useRouter} from 'vue-router'
    const router=useRouter()
    const data:any=ref([
        {
            F_Id:0,
            F_Name:'',
            F_ARY:0,
            F_MinMoney:0,
            F_Number:0,
            F_Level:0,
        }
    ])
    const PageInfo=ref(
        {
            PageIndex:1,
            PageCount:0,
            PageSize:2,
            ReCount:0
        }
    )
    const info=ref({
        Fid:0,
        Fname:'',
        Max:'',
        Min:''
    })
    onMounted(()=>{
        PageShow()
    })
    const PageShow=()=>{
        axios.get('https://localhost:44358/api/Finan/PageShow',
            {
                params:{
                    PageIndex:PageInfo.value.PageIndex,
                    PageSize:PageInfo.value.PageSize,
                    Fid:info.value.Fid,
                    Fname:info.value.Fname,
                    Min:info.value.Min,
                    Max:info.value.Max
                }
            }
        ).then(res=>{
            data.value=res.data.list
            PageInfo.value.PageCount=res.data.PageCount
            PageInfo.value.ReCount=res.data.ReCount
            console.log(res.data)
        })
        .catch(err=>{
            console.log(err)
        })
    }
    const PageChange=(msg:string)=>{
        if(msg=="F"){
            PageInfo.value.PageIndex=1
        }
        if(msg=="L"){
            PageInfo.value.PageIndex=PageInfo.value.PageCount
        }
        if(msg=="P"){
            if(PageInfo.value.PageIndex==1){
                alert("已经是第一页")
                return
            }
            PageInfo.value.PageIndex=PageInfo.value.PageIndex-1
        }
        if(msg=="N"){
            if(PageInfo.value.PageIndex==PageInfo.value.PageCount){
                alert("已经是最后一页")
                return
            }
            PageInfo.value.PageIndex=PageInfo.value.PageIndex+1
        }
        PageShow()
    }
const Go=(F_Id:number)=>{
    router.push(
        {
            path:'/SelectUserFinan',
            query:{
                F_Id:F_Id
            }
        }
    )
}

    </script>